@dir=('BRCA','BLCA','COAD','KIRC','LAML','LGG','LUAD','PRAD','READ','LUSC','OV','GBM');
for($i=0;$i<@dir;$i++)
{
	print "processing $dir[$i]\n";
	$dir=$dir[$i];
	system("mkdir /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir");
	open(WRBUFF,">/data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/runsh_it_$dir") or die " no file exists runshapeit\n";
	print WRBUFF '#! /bin/bash'."\n";
	print WRBUFF '#$ -q 1-day'."\n";
	print WRBUFF '#$ -l h_vmem=10G'."\n";
	print WRBUFF '#$ -M naresh.prodduturi@mayo.edu'."\n";
	print WRBUFF '#$ -m a'."\n";
	print WRBUFF '#$ -V'."\n";
	print WRBUFF '#$ -cwd'."\n";
	$sys="perl /data4/bsi/RandD/Workflow/genotyping_QC_FWD/perl_upgrade_build36_files_for_brainspore.pl  /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal.tped /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/fwdStrandResults_all_merged_removeddup_normal_build37.tped /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/fwdStrandResults_all_merged_removeddup_normal_build36.tped";
	print WRBUFF $sys."\n";
	$sys="cp /data2/bsi/RandD/Arraybased_RND/tcga_genotyping/results/$dir/NORMAL/fwdStrandResults_all_merged_removeddup_normal.tfam /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/fwdStrandResults_all_merged_removeddup_normal_build37.tfam";
	#print WRBUFF $sys."\n";
	system($sys);
	$sys="/data4/bsi/RandD/Workflow/genotyping_QC_FWD/bin/plink/plink --tfile /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/fwdStrandResults_all_merged_removeddup_normal_build37 --chr 8 --from-kb 126000 --to-kb 133000 --maf 0.00001 --make-bed --out /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/chr8q24_$dir";
	print WRBUFF $sys."\n";
	$sys="/data4/bsi/RandD/Workflow/genotyping_1000genome_impute/bin/shapeit  --input-bed  /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/chr8q24_$dir.bed /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/chr8q24_$dir.bim /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/chr8q24_$dir.fam --input-map /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/genetic_map_chr8_combined_b37.txt  --output-max  /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/chr8q24_$dir.haps /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/chr8q24_$dir.sample  --seed 123456789 --states-phase 100";
	print WRBUFF $sys."\n";
	$sys="gzip /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/chr8q24_$dir.haps";
	print WRBUFF $sys."\n";
	$sys="/data4/bsi/RandD/Workflow/genotyping_1000genome_impute/bin/impute_v2.2.2_x86_64_static/impute2 -use_prephased_g -allow_large_regions -m /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/genetic_map_chr8_combined_b37.txt -h /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/ALL_1000G_phase1integrated_feb2012_chr8_impute.hap.gz -l /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/ALL_1000G_phase1integrated_feb2012_chr8_impute.legend.gz -int 126000000 133000000 -known_haps_g /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/chr8q24_$dir.haps.gz -o /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/impute_8q24_out";
	print WRBUFF $sys."\n";
	$numsamp=`wc -l  /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/fwdStrandResults_all_merged_removeddup_normal_build37.tfam`;
	$numsamp=~ s/ .+//g;
	print $numsamp."\n";
	$sys= "perl /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/kk.pl /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/beagle1.gz $numsamp";
	system($sys);
	#print WRBUFF $sys."\n";
	$sys = "cut -f2,4- -d ' ' /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/impute_8q24_out|gzip > /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/beagle2.gz";
	print WRBUFF $sys."\n";
	$sys ="zcat /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/beagle1.gz /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/beagle2.gz |/usr/java/latest/bin/java  -Xmx3000m -jar /data4/bsi/RandD/Workflow/genotyping_1000genome_impute/bin/gprobsmetrics.jar |gzip > /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/beagle.r2.gz";
	print WRBUFF $sys."\n";	
	system("qsub /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/$dir/runsh_it_$dir");
}
